📚 node [[python how to write test units|write test units!]]
Welcome! Nobody has contributed anything to 'python how to write test units|write test units!' yet. You can:
-
Write something in the document below!
- There is at least one public document in every node in the Agora. Whatever you write in it will be integrated and made available for the next visitor to read and edit.
- Write to the Agora from social media.
-
Sign up as a full Agora user.
- As a full user you will be able to contribute your personal notes and resources directly to this knowledge commons. Some setup required :)
⥅ related node [[python how to write test units]]
⥅ node [[python-how-to-write-test-units]] pulled by Agora
Fail Fast
When you aren't sure what's going to happen or there's some ambiguity about whether something will work, raise an exception and fail right there and then with an explanation of what went wrong so you can avoid having to dig through fucking tracebacks for 2 hours.
class TestMaintMode:
@pytest.mark.asyncio
async def test_maint_mode(self, bot, aresponses):
# given/prep/arrange
# when/act/do
# then/assert/check
- Establish test class
- Decorator marks test as async
- Define sync function
- These three are the basic structure of how all tests work
Using Pytest
- Create a python file whose name starts with "test_"
- Either import or begin the file with the function or functions you'd like to test
- Define a number of test functions that take the same arguments as the function/s being tested
assert
a call to the function==
a certain value that you know should be true- Try cover all possible cases for the function in your tests
- Go to the working directory for that file
- run the command
pytest
- Pytest will run and tell you how many tests succeeded and how many failed.
📖 stoas
- public document at doc.anagora.org/python-how-to-write-test-units|write-test-units!
- video call at meet.jit.si/python-how-to-write-test-units|write-test-units!
⥱ context
↑ pushing here
(none)
(none)
↓ pulling this
(none)
(none)
→ forward
(none)
(none)
🔎 full text search for 'python how to write test units|write test units!'